package cluster

type Cluster struct {
	nodes        []*Node
	nodeNum      int
	masterNodeId int
	idMap        map[int]*Node
}

func NewCluster() *Cluster {
	return &Cluster{
		nodes:   nil,
		nodeNum: 0,
	}
}

func (c *Cluster) AddNode(node *Node) {
	c.idMap[node.Id] = node
	c.nodes = append(c.nodes, node)
	if c.nodeNum == 0 {
		c.masterNodeId = node.Id
	}
	c.nodeNum += 1
}

func (c *Cluster) DeleteNode(node *Node) {
	c.idMap[node.Id] = node

	delete(c.idMap, node.Id)
	if c.nodeNum == 1 {
		c.masterNodeId = -1
	}
	c.nodeNum -= 1
}
